import * as types from '../mutation-types'
import {getMsg} from 'api/message'

const state = {
  'messages': {}
}
const getters = {
  'messages': state => state.messages
}
const actions = {
  setMessage({commit}, {token}) {
    return getMsg(token).then((res) => {
      if (res.success === false) {
        return res
      } else {
        commit(types.SET_MY_COLLECT, res.data)
        return res
      }
    })
  }
}
const mutations = {
  [types.SET_MY_MESSAGE](state, value) {
    state.messages = value
  }
}

export default {
  state,
  getters,
  mutations,
  actions
}
